#include "vtkYorungeNoktasal.h"


//====================================================================================================================//
vtkYorungeNoktasal::vtkYorungeNoktasal(YorungeId id) : vtkYorunge(id)
{
	m_points = vtkSmartPointer<vtkPoints>::New();
	m_points_polydata = vtkSmartPointer<vtkPolyData>::New();
	m_polydata = vtkSmartPointer<vtkPolyData>::New();
	m_filter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
	m_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	m_actor = vtkSmartPointer<vtkActor>::New();
	
	aktorEkle(m_actor);

	// update pipeline
	guncelle();
}

//====================================================================================================================//
vtkYorungeNoktasal::~vtkYorungeNoktasal()
{}

//====================================================================================================================//
void vtkYorungeNoktasal::pozisyonEkle( const Pozisyon& pozisyon )
{
	vtkIdType id = m_points->InsertNextPoint(
		pozisyon.koordinat->x,
		pozisyon.koordinat->y,
		pozisyon.koordinat->z);

	// Renk dizinini guncelle.
	Colors()->InsertNextValue(static_cast<float>(id));
	guncelle();
}

//====================================================================================================================//
void vtkYorungeNoktasal::guncelle()
{
	m_points_polydata->SetPoints(m_points);
	
	m_filter->SetInputConnection(m_points_polydata->GetProducerPort());
	m_filter->Modified();
	m_filter->Update();

	m_polydata->ShallowCopy(m_filter->GetOutput());	

	// TODO(MEHMET): Renkler her yorunge icin farkli olmali, HSV degerleri kullanilabilir.
	vtkSmartPointer<vtkLookupTable>	 lut = Lut();
	lut->SetTableRange(0, m_points->GetNumberOfPoints());
	lut->SetHueRange (0.667, 0.0);
	lut->SetSaturationRange (1, 1);
	lut->SetValueRange (1, 1);
	lut->Build();
	vtkSmartPointer<vtkFloatArray> color = Colors();
	color->SetNumberOfComponents(1);
	color->SetName("Colors");
	
	m_polydata->GetPointData()->SetScalars(color);
	
	m_mapper->SetInputConnection(m_polydata->GetProducerPort());
	m_mapper->SetColorModeToMapScalars();
	m_mapper->SetLookupTable(lut);
	m_mapper->SetScalarRange(0,m_points->GetNumberOfPoints()-1);

	m_actor->SetMapper(m_mapper);
	m_actor->GetProperty()->SetPointSize(5);
}

